package com.dengpp.pdform.view;


import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.bumptech.glide.Glide;
import com.dengpp.pdform.R;

public class ImagePreviewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_preview);

        initViews();
        loadImage();
    }

    private void initViews() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle(getIntent().getStringExtra("image_title"));
        }

        toolbar.setNavigationOnClickListener(v -> finish());

        // 添加点击关闭功能
        ImageView imageView = findViewById(R.id.iv_preview);
        imageView.setOnClickListener(v -> finish());
    }

    private void loadImage() {
        String imageUriString = getIntent().getStringExtra("image_uri");
        if (imageUriString != null) {
            Uri imageUri = Uri.parse(imageUriString);
            ImageView imageView = findViewById(R.id.iv_preview);

            Glide.with(this)
                    .load(imageUri)
                    .error(R.drawable.library_ic_image_placeholder)
                    .into(imageView);
        }
    }
}
